package com.qfedu.inspectionTask.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qfedu.inspectionTask.dto.InspectionDto;
import com.qfedu.inspectionTask.mapper.InspectionMapper;
import com.qfedu.inspectionTask.pojo.Inspection;
import com.qfedu.inspectionTask.service.InspectionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

/**
 * 功能：
 * 作者：coding
 * 日期：2024/6/14 9:21
 */
@Service
public class InspectionServiceImpl extends ServiceImpl<InspectionMapper, Inspection> implements InspectionService {
    @Transactional(readOnly = true)
    @Override
    public Page<Inspection> getInspectionTasks(InspectionDto inspectionDto) {
        LambdaQueryWrapper<Inspection> wrapper=new LambdaQueryWrapper<>();
        wrapper.select(Inspection::getId,Inspection::getName,Inspection::getLineId,
                    Inspection::getStartNumber,Inspection::getEndNumber,Inspection::getState,
                    Inspection::getInspectionUser);
        //下面都是搜索成功需要添加的相关条件
        String name = inspectionDto.getName();
        wrapper.like(StringUtils.hasLength(name),Inspection::getName,name);
        String inspectionUser = inspectionDto.getInspectionUser();
        wrapper.eq(StringUtils.hasLength(inspectionUser), Inspection::getInspectionUser, inspectionUser);
        String lineId = inspectionDto.getLineId();
        wrapper.like(StringUtils.hasLength(lineId),Inspection::getLineId,lineId);
        String startNumber =inspectionDto.getStartNumber();
        wrapper.like(StringUtils.hasLength(startNumber),Inspection::getStartNumber,startNumber);
        String endNumber =inspectionDto.getEndNumber();
        wrapper.like(StringUtils.hasLength(endNumber),Inspection::getEndNumber,endNumber);
        Integer state = inspectionDto.getState();
        wrapper.eq(state != null, Inspection::getState, state);
        Page<Inspection> page = new Page<>(inspectionDto.getCurrentPage(), inspectionDto.getPageSize());
        return page(page,wrapper);
    }

}
